package com.actor;

/**
 * @author Dmitry
 */
public class Future {
    private FutureCallback onSuccess;
    private FutureErrorCallback onError;
    private FutureCallback onComplete;

    public Future() {
    }

    public FutureCallback getOnSuccess() {
        return onSuccess;
    }

    public Future setOnSuccess(FutureCallback onSuccess) {
        this.onSuccess = onSuccess;
        return this;
    }

    public FutureErrorCallback getOnError() {
        return onError;
    }

    public Future setOnError(FutureErrorCallback onError) {
        this.onError = onError;
        return this;
    }

    public FutureCallback getOnComplete() {
        return onComplete;
    }

    public Future setOnComplete(FutureCallback onComplete) {
        this.onComplete = onComplete;
        return this;
    }

    void onSuccess(Object value, ActorRef sender) {
        if (onSuccess != null) {
            onSuccess.callback(value, sender);
        }
    }

    void onError(Object value, Throwable error, ActorRef sender) {
        if (onError != null) {
            onError.errorCallback(value, error, sender);
        }
    }

    void onComplete(Object value, ActorRef sender) {
        if (onComplete != null) {
            onComplete.callback(value, sender);
        }
    }
}
